package com.jic.veteran.controller;

import com.jic.veteran.common.api.CommonPage;
import com.jic.veteran.common.api.CommonResult;
import com.jic.veteran.model.PayInfo;
import com.jic.veteran.model.ReconResult;
import com.jic.veteran.service.ReconResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "PayInfoController")
@Controller
@RequestMapping("/payInfo")
public class PayInfoController {

    @Autowired
    ReconResultService reconResultService;

    @ApiOperation("查询支付信息列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<PayInfo>> list(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<PayInfo> payInfoList = reconResultService.getPayInfoList(pageSize,pageNum);
        return CommonResult.success(CommonPage.restPage(payInfoList));
    }

    @ApiOperation("更新支付信息")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updatePayInfo(@PathVariable Long id,@RequestParam(value = "status") String status) {

        int result = reconResultService.updatePayInfo(id,status);
        if (result > 0) {
            return CommonResult.success(result);
        } else if (result == -1) {
            return CommonResult.failed("只能有一个启用的支付信息");
        } else if (result == -2) {
            return CommonResult.failed("必须系统中必须有一个启用的支付信息");
        }
        return CommonResult.failed();
    }
}
